var Page = function(){
    this.init();
};
Page.prototype = {
    params: {
        passport: '',
        memberId:'',
        page: 1,
        listRows: 10,
        total: 0,
        orderMember:'',
        state:'',
        gmtStart:'',
        gmtEnd:'',

    },
    init: function(){
        this.initParams();
        this.initEvent();
    },
    initParams: function(){
        this.params.passport = Pub.getCookie('_PASSPORT');
        this.params.memberId = Pub.getSession('memberId');
    },
    getData: function(){
        var _this = this;
        var paramsObj = {
            passport: _this.params.passport,
            memberId: _this.params.memberId,
            page: _this.params.page,
            listRows: _this.params.listRows,
            orderMember: _this.params.orderMember,
            state: _this.params.state,
            gmtStart: _this.params.gmtStart,
            gmtEnd: _this.params.gmtEnd,
        };
        Api.memberlistdetails(paramsObj, function(data){
            console.log(data);

            $('#top_memberNumber').text(data.data[0].memberNumber);
            $('#top_memberName').text(data.data[0].memberName);
            $('#top_mobile').text(data.data[0].mobile);
            $('#top_unitName').text(data.data[0].unitName);
            _this.getDataList(data.list);
            _this.params.total = data.totalPages;
            layui.use('laypage', function() {
                var laypage = layui.laypage;
                //执行一个laypage实例
                laypage.render({
                    elem: 'page',
                    index: 1,
                    theme: '#3498db',
                    curr: _this.params.page,
                    count: _this.params.total, //数据总数，从服务端得到
                    hash: 'curr_page',
                    layout: ['prev', 'page', 'next', 'skip'],
                    jump: function(obj, first) {
                        _this.params.page = obj.curr;
                        //obj包含了当前分页的所有参数，比如：curr当前页
                        var Params = {
                            passport: _this.params.passport,
                            memberId: _this.params.memberId,
                            page: _this.params.page,
                            listRows: _this.params.listRows,
                            orderMember: _this.params.orderMember,
                            state: _this.params.state,
                            gmtStart: _this.params.gmtStart,
                            gmtEnd: _this.params.gmtEnd,
                        };
                        Api.memberlistdetails(Params, function(data) {
                            _this.getDataList(data.list);
                            $('#top_memberNumber').text(data.data[0].memberNumber);
                            $('#top_memberName').text(data.data[0].memberName);
                            $('#top_mobile').text(data.data[0].mobile);
                            $('#top_unitName').text(data.data[0].unitName);
                        })
                    }
                });
            });
        });
    },
    getDataList: function(data) {
        var _this = this;
        console.log(data);
        if (data && data.length > 0) {
            var html = '',
                i = 0,
                len = data.length;
            for (i; i < len; i++) {
                html += '<tr>' +
                        '<td class="text-c">' + data[i].orderNumber + '</td>' +
                        '<td class="text-c">' + data[i].gmtCreate + '</td>';
                if (data[i].state==40) {
                    html += '<td class="text-c">已入库</td>';
                }else if (data[i].state==50) {
                    html += '<td class="text-c">封箱</td>';
                }else if (data[i].state==55) {
                    html += '<td class="text-c">拆箱</td>';
                }else if (data[i].state==60) {
                    html += '<td class="text-c">出库</td>';
                }else if (data[i].state==65) {
                    html += '<td class="text-c">中转</td>';
                };
                html +='</tr>'
            }
            $('#orderList').html(html);
            $('tfoot').css('display', 'table-footer-group');
        } else {
            var html = '<tr>' +
                '<td class="text-c c-666" colspan="3" >暂无数据</td>' +
                '</tr>';
            $('#orderList').html(html);
            $('tfoot').css('display', 'none');
        }
    },
    otherEvent:function(){
        var _this = this;
        $('.goods-checkbox input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        })
        $('.slectShow').click(function(event) {
            $('.select-wrap').toggle(400);
        });
        $('#changeSize').on('change', function(event) {
            event.preventDefault();
            _this.params.listRows = $(this).val();
            _this.params.page=1;
            $('#page').html('');
            _this.getData();
        });
        layui.use('laydate', function() {
            var laydate = layui.laydate;
            laydate.render({
                elem: '#time',
                range: '~',
                done: function(value, date, endDate) {
                    console.log(date);
                    if (date.year) {
                        if (date.month < 10) {
                            date.month = "0" + date.month;
                        }
                        if (date.date < 10) {
                            date.date = "0" + date.date;
                        }
                        if (endDate.month < 10) {
                            endDate.month = "0" + endDate.month;
                        }
                        if (endDate.date < 10) {
                            endDate.date = "0" + endDate.date;
                        }
                        var gmtStart = date.year + '-' + date.month + '-' + date.date + ' 00:00:00';
                        var gmtEnd = endDate.year + '-' + endDate.month + '-' + endDate.date + ' 00:00:00';
                        _this.params.gmtStart = gmtStart;
                        _this.params.gmtEnd = gmtEnd;

                    } else {
                        _this.params.gmtStart = '';
                        _this.params.gmtEnd = '';
                    };
                }
            });
        });
        $('#normalSearch').click(function(event) {
            _this.params.memberNumber=$('#memberNumber').val();
            _this.params.page=1;
            _this.getData();
        });
        $('#orderState').on('change', function(event) {
            event.preventDefault();
            _this.params.state = $(this).val();
        });
    },
    initEvent: function(){
        var _this = this;
         _this.getData();
        _this.otherEvent();


    }
};
var page = new Page();